package com.lemon.smartsafety.ui.adapter.fire;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.mode.adapter.LampMode;
import com.lemon.smartsafety.utils.CommonUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 项目名称：workspace
 * 类描述：
 * 创建人：Fargo
 * 创建时间：2016/8/9 14:05
 * 修改人：Fargo
 * 修改时间：2016/8/9 14:05
 * 修改备注：
 */
public class LampCenterAdapter extends BaseAdapter {

    /**
     * TAG
     */
    private final String TAG = "LampCenterAdapter";

    /**
     * 选择项
     */
    private int m_nSelectItem = -1;

    /**
     * 数据列表
     */
    private List<LampMode> mList;


    /**
     * 布局泵
     */
    private LayoutInflater m_layInflater = null;

    private Context mContext;

    //是否显示右箭头
    private boolean isShowArrowRight = true;


    public boolean isShowArrowRight() {
        return isShowArrowRight;
    }

    public void setShowArrowRight(boolean showArrowRight) {
        isShowArrowRight = showArrowRight;
    }

    /**
     * 设置选择项
     *
     * @param n
     */
    public void setSelectItem(final int n) {
        m_nSelectItem = n;
    }

    /**
     * 设置数据列表
     */
    public void setList(ArrayList<LampMode> list) {
        this.mList = list;
    }

    /**
     * 构造函数
     *
     * @param context
     */
    public LampCenterAdapter(Context context, List<LampMode> list) {
        try {
            this.mContext = context;

            this.mList = list;

            // 布局泵
            m_layInflater = LayoutInflater.from(context);

        } catch (Exception e) {
        }
    }

    @Override
    public int getCount() {
        try {
            if (mList != null)
                return mList.size();
        } catch (Exception e) {
        }

        return 0;
    }

    @Override
    public Object getItem(int position) {
        try {
            if (mList != null)
                return mList.get(position);
        } catch (Exception e) {
        }

        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressWarnings({"deprecation"})
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        try {
            //内容
            final ViewHolder holder;
            if (convertView == null) {
                convertView = m_layInflater.inflate(R.layout.item_lamp_center_list, null);
                holder = new ViewHolder(convertView);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            if (mList.get(position).getType() == 0) {
                holder.ReyAll.setVisibility(View.VISIBLE);
                holder.lineAll.setVisibility(View.GONE);

                holder.txtTitle.setText(mList.get(position).getTitle());
                holder.txtNum.setText(mList.get(position).getNum());
                if (mList.get(position).isShowCircle()) {
                    holder.imageCircle.setVisibility(View.VISIBLE);
                } else {
                    holder.imageCircle.setVisibility(View.GONE);
                }
                if (mList.get(position).getDrawable() != -1) {
                    holder.imageCircle.setBackgroundResource(mList.get(position).getDrawable());
                }

                if (isShowArrowRight) {
                    holder.arrowRight.setVisibility(View.VISIBLE);
                } else {
                    holder.arrowRight.setVisibility(View.INVISIBLE);
                }

                if(CommonUtil.strIsEmpty(mList.get(position).getSub())){
                    holder.txtSub.setVisibility(View.GONE);
                }else{
                    holder.txtSub.setVisibility(View.VISIBLE);
                    holder.txtSub.setText(mList.get(position).getSub());
                }


            }
            //标题
            else {
                holder.ReyAll.setVisibility(View.GONE);
                holder.lineAll.setVisibility(View.VISIBLE);

                holder.textView.setText(mList.get(position).getTitle());

            }


        } catch (Exception e) {
            e.printStackTrace();
        }

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.txt_title)
        TextView txtTitle;
        @Bind(R.id.txt_sub)
        TextView txtSub;
        @Bind(R.id.txt_num)
        TextView txtNum;
        @Bind(R.id.line_num)
        LinearLayout lineNum;
        @Bind(R.id.image_circle)
        ImageView imageCircle;
        @Bind(R.id.arrow_right)
        TextView arrowRight;
        @Bind(R.id.ReyAll)
        RelativeLayout ReyAll;
        @Bind(R.id.textView)
        TextView textView;
        @Bind(R.id.lineAll)
        LinearLayout lineAll;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }


    /**
     * 项支持器类
     */


}
